<template>
  <div class="app-container home">
    <el-row :gutter="20" style="padding-bottom: 20px">
      <el-col :span="6" style="padding-left: 20px">
        <el-card>
          <div class="body">
            <el-statistic title="在售课程">
              <template slot="formatter">
                6
              </template>
            </el-statistic>
          </div>
        </el-card>

      </el-col>
      <el-col :span="6">
        <el-card>
          <div class="body">
            <el-statistic title="在校老师">
              <template slot="formatter">
                6
              </template>
            </el-statistic>
          </div>
        </el-card>

      </el-col>
      <el-col :span="6">
        <el-card>
          <div class="body">
            <el-statistic title="在校学生">
              <template slot="formatter">
                6
              </template>
            </el-statistic>
          </div>
        </el-card>

      </el-col>
      <el-col :span="6">
        <el-card>
          <div class="body">
            <el-statistic title="男女比例">
              <template slot="formatter">
                3/2
              </template>
            </el-statistic>
          </div>
        </el-card>

      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :sm="24" :lg="12" style="padding-left: 20px">
        <el-row>
          <el-col :span="24">
            <el-card class="update-log">
              <div slot="header" class="clearfix">
                <span>今日课程({{ parseTime(selectedDay, '{y}-{m}-{d}') }})</span>
              </div>
              <div class="body">
                <el-table v-loading="loading" :data="schoolTimetable" empty-text="暂无课程">
                  <el-table-column label="课程" align="center" prop="subjectName"/>
                  <el-table-column label="任课老师" align="center" prop="teacher"/>
                  <el-table-column label="上课时间" align="center" width="180">
                    <template slot-scope="scope">
                      <span>{{
                          parseTime(scope.row.timeSlot[0], '{h}:{i}')
                        }} 至 {{ parseTime(scope.row.timeSlot[1], '{h}:{i}') }}</span>
                    </template>
                  </el-table-column>
                </el-table>

              </div>
            </el-card>
          </el-col>
        </el-row>
        <el-row style="padding-top: 20px">
          <el-col :span="24">
            <el-card class="update-log">
              <div slot="header" class="clearfix">
                <span>照片墙</span>
              </div>
              <div class="body">
                <el-carousel height="400px">
                  <el-carousel-item>
                    <img src="../assets/images/1.jpg" alt="" style="width: 100%; height: 500px;">
                  </el-carousel-item>
                  <el-carousel-item>
                    <img src="../assets/images/2.jpeg" alt="" style="width: 100%; height: 500px;">
                  </el-carousel-item>
                  <el-carousel-item>
                    <img src="../assets/images/3.jpeg" alt="" style="width: 100%; height: 500px;">
                  </el-carousel-item>
                  <el-carousel-item>
                    <img src="../assets/images/4.jpeg" alt="" style="width: 100%; height: 500px;">
                  </el-carousel-item>
                </el-carousel>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-col>

      <el-col :sm="24" :lg="12">
        <el-card class="update-log">
          <div class="body">
            <el-calendar v-model="currentDay">
              <template #dateCell="{ data }">
                <!-- .self确保点击单元格本身才触发 -->
                <div class="custom-cell" @click.stop="handleCustomClick(data)">
                  {{ data.day.split('-')[2] }}
                </div>
              </template>
            </el-calendar>
          </div>
        </el-card>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getSchoolTimetable } from '@/api/edu/subjects'
import { validateTenantExpire } from '@/api/system/dept'
import { MessageBox } from 'element-ui'

export default {
  name: 'Index',
  data() {
    return {
      // 版本号
      version: '3.8.9',
      currentDay: new Date(),
      selectedDay: new Date(),
      schoolTimetable: [],
      loading: false
    }
  },
  created: function() {
    this.handleSchoolTimetable(this.parseTime(this.selectedDay, '{y}-{m}-{d}'))
    this.notifyTenantExpire()
  },
  methods: {
    handleCustomClick(cellData) {
      if (cellData.type === 'current-month') {
        this.selectedDay = cellData.day
        this.handleSchoolTimetable(this.selectedDay)
      }
    },
    handleSchoolTimetable(day) {
      getSchoolTimetable(day).then(response => {
        this.schoolTimetable = response.data
      })
    },
    notifyTenantExpire() {
      validateTenantExpire().then(response => {
        if (response.data.code !== 200) {
          this.$modal.alertWarning(response.data.msg)
        }
      })

    }
  }
}
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }

  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }

  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }

  .custom-cell {
    height: 100%;
    padding: 8px;
    cursor: pointer;
  }

}
</style>

